/*
day237
2020.4.21
*/ 
#include<iostream>
#include<vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    vector<int> flipMatchVoyage(TreeNode* root, vector<int>& voyage) {
		vector<int> res;
		int index=0;
		if(help(root,res,voyage,index))
		{
			return res;
		}
		return {-1};
    }
    
    bool help(TreeNode* root,vector<int> &res,vector<int>& voyage,int &index)
    {
    	if(!root) return true;
    	
    	if(root->val!=voyage[index])
    	{
    		return false;
		}
		
		index++;
		
		if(root->left && root->left->val!=voyage[index])
		{
			TreeNode *tem=root->right;
			root->right=root->left;
			root->left=tem;
			
			res.push_back(root->val);
		}
		
		return help(root->left,res,voyage,index) && help(root->right,res,voyage,index);
	}
};

int main()
{
	return 0;
}
